package org.jctc.els.modules.biz.controller.pro;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.jctc.els.modules.biz.entity.pro.*;
import org.jctc.els.modules.biz.entity.projects.ElsProjects;
import org.jctc.els.modules.biz.service.pro.ElsProjectReviewService;
import org.jctc.els.modules.biz.service.projects.ElsProjectsService;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.annotation.MultipartConfig;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 评审表;(els_project_review)表控制层
 *
 * @author : http://www.chiner.pro
 * @date : 2022-6-21
 */
@Api(tags = "评审表对象功能接口")
@RestController
@RequestMapping("/elsProjectReview")
@NonDS
@ApiIgnore
@AllArgsConstructor
@MultipartConfig
public class ElsProjectReviewController extends BladeController {
    @Autowired
    private ElsProjectReviewService elsProjectReviewService;

    @Autowired
    private ElsProjectsService projectsService;


    @GetMapping("export/zgpx")
    @ApiOperationSupport(order = 13)
    @ApiOperation(value = "导出职工培训", notes = "传入项目id")
    public void exportZgpx(HttpServletResponse response,@RequestParam("projectName") String projectName,@RequestParam("teamId") Long teamId
            ,@RequestParam("status")Integer status) {
        Long baseRole = AuthUtil.getBaseRole();
        List<ProjectReviewZGPXExcel> zgpx = elsProjectReviewService.exportZGPX(baseRole,projectName,teamId,status);
        ExcelUtil.export(response, "教育培训储备项目评审数据汇总", "教育培训储备项目评审数据汇总", zgpx, ProjectReviewZGPXExcel.class);
    }

    @GetMapping("export/rcpj")
    @ApiOperationSupport(order = 13)
    @ApiOperation(value = "导出人才评价", notes = "传入项目id")
    public void export(HttpServletResponse response,@RequestParam("projectName") String projectName,@RequestParam("teamId") Long teamId
            ,@RequestParam("status")Integer status) {
        Long baseRole = AuthUtil.getBaseRole();
        List<ProjectReviewRCPJExcel> zgpx = elsProjectReviewService.exportRCPJ(baseRole,projectName,teamId,status);
        ExcelUtil.export(response, "教育培训储备项目评审数据汇总", "教育培训储备项目评审数据汇总", zgpx, ProjectReviewRCPJExcel.class);
    }

    @GetMapping("export/pxkf")
    @ApiOperationSupport(order = 13)
    @ApiOperation(value = "导出培训开发", notes = "传入项目id")
    public void exportPxkf(HttpServletResponse response,@RequestParam("projectName") String projectName,@RequestParam("teamId") Long teamId
            ,@RequestParam("status")Integer status) {
        Long baseRole = AuthUtil.getBaseRole();
        List<ProjectReviewPXKFExcel> pxkf = elsProjectReviewService.exportPXKF(baseRole,projectName,teamId,status);
        ExcelUtil.export(response, "教育培训储备项目评审数据汇总", "教育培训储备项目评审数据汇总", pxkf, ProjectReviewPXKFExcel.class);
    }

    @GetMapping("export/pxgz")
    @ApiOperationSupport(order = 13)
    @ApiOperation(value = "导出培训购置", notes = "传入项目id")
    public void exportPXGZ(HttpServletResponse response,@RequestParam("projectName") String projectName,@RequestParam("teamId") Long teamId
            ,@RequestParam("status")Integer status) {
        Long baseRole = AuthUtil.getBaseRole();
        List<ProjectReviewPXKFExcel> pxgz = elsProjectReviewService.exportPXGZ(baseRole,projectName,teamId,status);
        ExcelUtil.export(response, "教育培训储备项目评审数据汇总", "教育培训储备项目评审数据汇总", pxgz, ProjectReviewPXKFExcel.class);
    }

    @GetMapping("export/jgdx")
    @ApiOperationSupport(order = 13)
    @ApiOperation(value = "导出技改大修", notes = "传入项目id")
    public void exportJG(HttpServletResponse response,@RequestParam("projectName") String projectName,@RequestParam("teamId") Long teamId
            ,@RequestParam("status")Integer status) {
        Long baseRole = AuthUtil.getBaseRole();
        List<ProjectReviewJGExcel> pxgz = elsProjectReviewService.exportJG(baseRole,projectName,teamId,status);
        ExcelUtil.export(response, "教育培训储备项目评审数据汇总", "教育培训储备项目评审数据汇总", pxgz, ProjectReviewJGExcel.class);
    }

    @ApiOperation("组长评审审核")
    @PostMapping("/expert-audit")
    public R updateExpertAudit(@RequestBody ProjectReviewAudit expertAudit) {
        Boolean result = elsProjectReviewService.updateExpertAudit(expertAudit);
        return R.status(result);
    }

    @ApiOperation("管理员评审审核")
    @PostMapping("/admin-audit")
    public R updateAdminAudit(@RequestBody ProjectReviewAudit expertAudit) {
        Boolean result = elsProjectReviewService.updateAdminAudit(expertAudit);
        return R.status(result);
    }


    @ApiOperation("通过项目id以及专家查询表单")
    @GetMapping
    public R queryByProjectIdAndExpert(@RequestParam("projectId") Long projectId, @RequestParam("userId") Long userId) {
        ProjectReviewVO reviewVO = elsProjectReviewService.selectByProjectIdAndExpertId(projectId, userId);
        return R.data(reviewVO);
    }

    @ApiOperation("通过项目id查看专家打分情况")
    @GetMapping("/expert-score")
    public R<IPage<ProjectReviewAuditVO>> queryExpertScore(@RequestParam(value = "pageNum") Integer pageNum,
                                                           @RequestParam(value = "pageSize") Integer pageSize,
                                                           @RequestParam("projectId") Long projectId) {
        IPage<ProjectReviewAuditVO> auditList = elsProjectReviewService.selectExpertScore(pageNum, pageSize, projectId);
        return R.data(auditList);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @ApiOperation("通过ID查询单条数据")
    @GetMapping("{id}")
    public ResponseEntity<ElsProjectReview> queryById(Long id) {
        return ResponseEntity.ok(elsProjectReviewService.queryById(id));
    }


    /**
     * 新增数据
     *
     * @param elsProjectReview 实例对象
     * @return 实例对象
     */
    @ApiOperation("新增数据")
    @PostMapping
    public R add(@RequestBody ProjectReviewVO elsProjectReview) {
        Boolean result = elsProjectReviewService.insertAnswerProReview(elsProjectReview);
        return R.status(result);
    }

    /**
     * 更新数据
     *
     * @param elsProjectReview 实例对象
     * @return 实例对象
     */
    @ApiOperation("更新数据")
    @PutMapping
    public ResponseEntity<ElsProjectReview> edit(ElsProjectReview elsProjectReview) {
        return ResponseEntity.ok(elsProjectReviewService.update(elsProjectReview));
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @ApiOperation("通过主键删除数据")
    @DeleteMapping("{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(elsProjectReviewService.deleteById(id));
    }
}
